package com.rural.bus.driver.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Map;

public class CommonTools {

	public static boolean isEmpty(String para){
		if (para == null || para.trim().length() < 1){
			return true;
		}
		return false;
	}

	public static String inputStream2String(InputStream is){
		String str = "";
		StringBuffer out = new StringBuffer();
		byte[] b = new byte[5120];
		try {
			for (int n;(n = is.read(b)) != -1;)   {
				out.append(new String(b, 0, n));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		str = out.toString();
		return str;
	}

	/**
	 * 完成URL地址拼接
	 */
	public static String getUrlString(String url, Map<String, String> map) {
		StringBuffer sb = new StringBuffer(url);
		Map.Entry<String, String> entry;
		Object key;
		Object value;
		Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
		if (!map.isEmpty()) {
			sb.append("?");
		}
		boolean first = true;
		while (it.hasNext()) {
			if (!first) {
				sb.append("&");
			}
			first = false;
			entry = (Map.Entry<String, String>) it.next();
			key = entry.getKey();
			value = entry.getValue();
			sb.append(key.toString() + "=" + value.toString());

		}
		return sb.toString();
	}
}
